package collections;

import java.util.HashSet;
import java.util.Iterator;

public class HashSetTest {

	public static void main(String args[])
	{
		HashSet hs = new HashSet();
		/*
		hs.add("one");
		hs.add("two");
		hs.add("three");
		hs.add("three");
		
		Iterator it = hs.iterator();
		while(it.hasNext())
		{
			System.out.println(it.next());
		}
		*/
		hs.add(new Person("zhangsan",11));
		hs.add(new Person("lisi",12));
		hs.add(new Person("wangwu",13));
		hs.add(new Person("lisi",12));
		ArrayListTest.printElement(hs);
		
		/*
		System.out.println(new String("qq").hashCode());
		System.out.println("qq".hashCode());
		System.out.println(new MyQueue().hashCode());
		System.out.println(new MyQueue().hashCode());
		*/
	}
}

class Person
{
	String name;
	int age;
	public Person(String name,int age)
	{
		this.name = name;
		this.age = age;
	}
	public int hashCode()
	{
		return age*name.hashCode();
	}
	public boolean equals(Object o)
	{
		Person p=(Person)o;
		return name.equals(p.name) && age == p.age;
		//return this == o;
	}
	public String toString() {
		return "name="+name+" age="+age;
	}
}
